#!/usr/bin/python
# -*- coding: UTF-8 -*-
# Define your item pipelines here
#
# Don't forget to add your pipeline to the ITEM_PIPELINES setting
# See: https://doc.scrapy.org/en/latest/topics/item-pipeline.html
import json
import os


from unittest import signals
from scrapy import crawler
from scrapy.exporters import JsonItemExporter, JsonLinesItemExporter
from sklearn import pipeline
from ShopTrackingSpider import common


class ShoptrackingspiderPipeline(object):
    def process_item(self, item, spider):
        return item


pass

class DhgateShopPipeline(object):
    def process_item(self, item, spider):
        return item
    pass

class DhgateCategoriesListPipeline(object):

    def __init__(self):
        # base_dir = os.path.abspath('.') + "\\spiders\\dhgate"
        # jsonDir = base_dir + "\\categories_list.json"
        self.file = open(common.CommonUtil.PATH_DHGATE_CATEGORIES_JSON, 'wb')
        self.exporter = JsonItemExporter(self.file, ensure_ascii=False, encoding='utf-8')
        self.exporter.start_exporting()

    def process_item(self, item, spider):
        # print('DhgateCategoriesPipeline Write:')
        print(item['categorie'])
        print(item['name'])
        # print(item['url'])
        self.exporter.export_item(item)
        return item

    def close_spider(self, spider):
        # print('DhgateCategoriesPipeline Close')
        self.exporter.finish_exporting()
        self.file.close()




